﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KingerRobot.PCRBW.SpiService;

public static class CommHelper
{
  
    /// <summary>
    /// 时间差（秒）
    /// </summary>
    /// <param name="DateTime"></param>
    /// <returns></returns>
    public static double DateDiffSeconds(DateTime DateTime)
    {
        var now = new DateTime();
        var ts1 = new TimeSpan(now.Ticks);
        var ts2 = new TimeSpan(DateTime.Ticks);
        var ts = ts1.Subtract(ts2).Duration();
        // dateDiff = ts.Days.ToString() + "天" + ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分钟" + ts.Seconds.ToString() + "秒";

        return ts.TotalSeconds;
    }

    /// <summary>
    /// 获取数据库时间
    /// </summary>
    /// <returns></returns>
    public static DateTime GetNowTime()
    {
        var now = K8.CBB.XApp.Current.DbConfig.ToObject<K8.CBB.DbConfig>().Now;

        return now;
    }

    /// <summary>
    /// 获取枚举的显示名字
    /// </summary>
    /// <param name="en"> </param>
    /// <returns> </returns>
    public static string GetDisplayName(this System.Enum en)
    {
        var type = en.GetType();
        var memInfo = type.GetMember(en.ToString());
        if (memInfo != null && memInfo.Length > 0)
        {
            var attrs = memInfo[0].GetCustomAttributes(typeof(DisplayAttribute), true);
            if (attrs != null && attrs.Length > 0)
            {
                return ((DisplayAttribute)attrs[0]).Name;
            }
        }
        return en.ToString();
    }
}
